import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QLabel, QPushButton, QLineEdit, QVBoxLayout

class AnotherWindow(QWidget):
    def __init__(self):
        super().__init__()

        layout = QVBoxLayout()
        self.label = QLabel("Another Window")
        layout.addWidget(self.label)

        self.setLayout(layout)

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.w = AnotherWindow()
        self.setWindowTitle("My App")
        layout = QVBoxLayout()
        self.input = QLineEdit()
        self.input.textChanged.connect(self.w.label.setText)
        layout.addWidget(self.input)

        button = QPushButton("Press me for a window")
        button.clicked.connect(self.button_clicked)
        layout.addWidget(button)

        widget = QWidget()
        widget.setLayout(layout)
        
        self.setCentralWidget(widget)

    def button_clicked(self):
        if self.w.isVisible():
            self.w.hide()
        else:
            self.w.show()

app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()
